home *** CD-ROM | disk | FTP | other *** search
- @echo off
- ! deldir.bat Batch file to delete a folder with all its content
- !
- ! deldir name
- !
- ! where 'name' is the folder to be deleted. It can be preceded by a path and a
- ! volume ID.
- !
- ! Copyright © 1993 by Rainbow Hill Pty Ltd. All rights reserved.
- !
- set tempfile=TEMP7777
-
- ! ensure that the first parameter is there and that the third one is not
- set doserr=13
- if not "%3 " == " " goto ERR_LBL
- if "%1 " == " " goto ERR_LBL
-
- ! Check whether the second parameter is there. If not, find out where you are
- ! and save the current path in a global variable
- if not "%2 " == " " goto SKIP_HEADER_LBL
- set returnFolder=%WHERE%
- echo Folders being deleted:
- :SKIP_HEADER_LBL
- echo "%1"
-
- ! change to the folder to be deleted
- cd "%1"
-
- ! Prepare a file with the list of all subfolders.
- onerror DIRERR_LBL
- dir /b/a-f > %tempfile%
- goto DIR_OK_LBL
- :DIRERR_LBL
- if not %doserr% == 27 goto ERR_LBL
- ! there are no subfolders, but there could still be files
- goto DELFILES_LBL
- :DIR_OK_LBL
-
- ! open the file containing the list of all subfolders
- open %tempfile% fileID
-
- ! save the fileID into a file to make deldir re-entrant
- open/w theFileID id
- write %id% %fileID%
- close %id%
-
- set doserr=0
- onerror X_DELDIR_LOOP_LBL
- repeat DELDIR_LOOP_LBL
-
- ! obtain the folder name
- read %fileID% aDir
- ! remove the double quotes which enclose the names
- decr aDir
- decr -aDir
-
- ! Execute deldir recursively to remove the subfolder.
- ! Pass the 'parent path' as second parameter, so that it will come back
- call deldir "%aDir%" ".."
-
- ! restore the fileID
- open theFileID id
- read %id% fileID
- close %id%
-
- ! now that the fileID is ok, check whether deldir returned an error
- if %doserr% == 0 goto CONTINUE_LOOP_LBL
- close %fileID%
- goto DONE_LBL
-
- :CONTINUE_LOOP_LBL
- :DELDIR_LOOP_LBL
- :X_DELDIR_LOOP_LBL
- if not %doserr% == 3 goto ERR_LBL
-
- :DELFILES_LBL
- ! Now that we have removed all the subfolders, we can delete all the files, including
- ! the temporary files which we have created.
- ! Remember that MacDOS does not prompt for confirmation when you want to delete everything
- ! if you are in batch mode.
- onerror ERR_LBL
- del *
-
-
- ! finally, reset the global variables and remove the current folder
- set fileID=
- set id=
- set aDir=
- set doserr=0
- if "%2 " == " " goto TOP_FOLDER_LBL
- cd "%2"
- goto ANY_FOLDER_LBL
- :TOP_FOLDER_LBL
- cd ..
- cd "%returnFolder%"
- set returnFolder=
- set tempfile=
- :ANY_FOLDER_LBL
- rd "%1"
- goto DONE_LBL
-
- :ERR_LBL
- show %doserr%
-
- :DONE_LBL
-